package com.platform.common.utils;

import com.platform.common.functions.BranchHandle;
import com.platform.common.functions.PresentOrElseHandler;
import com.platform.common.functions.ThrowExceptionFunction;

public class VUtils {

    /**
     * 如果参数为true抛出异常
     * @param b
     * @return
     */
    public static ThrowExceptionFunction isTrue(boolean b){
        return errorMessage ->{
            if(b){
                throw new RuntimeException(errorMessage);
            }
        };
    }

    public static BranchHandle isTrueOrFalse(boolean b){
        return ((trueHandle,falseHandle) -> {
           if(b) {
               trueHandle.run();
           }else {
               falseHandle.run();
           }
        });
    }

    /**
     *
     * @param str
     * @return
     */
    public static PresentOrElseHandler<?> isBlankOrNotBlank(String str){
        return (consumer, runnable) -> {
            if( str == null || str.length() == 0){
                runnable.run();
            }else {
                consumer.accept(str);
            }
        };
    }
}
